﻿using Common.FrontEnd;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Common
{
    public interface IMixtureComponent
    {
        /**
        /// Returns the mean for this component.
         *
        /// @return the mean
         */
        float[] getMean();


        /**
        /// Returns the variance for this component.
         *
        /// @return the variance
         */
        float[] getVariance();

        /**
        /// Calculate the score for this mixture against the given feature.
        /// <p/>
        /// Note: The support of <code>DoubleData</code>-features would require an array conversion to
        /// float[]. Because getScore might be invoked with very high frequency, features are restricted
        /// to be <code>FloatData</code>s.
         *
        /// @param feature the feature to score
        /// @return the score, in log, for the given feature
         */
        float getScore(IFloatData feature);


        /**
        /// Calculate the score for this mixture against the given feature. We model the output
        /// distributions using a mixture of Gaussians, therefore the current implementation is simply
        /// the computation of a multi-dimensional Gaussian. <p/> <p><b>Normal(x) = exp{-0.5/// (x-m)' *
        /// inv(Var)/// (x-m)} / {sqrt((2/// PI) ^ N)/// det(Var))}</b></p>
        /// <p/>
        /// where <b>x</b> and <b>m</b> are the incoming cepstra and mean vector respectively,
        /// <b>Var</b> is the Covariance matrix, <b>det()</b> is the determinant of a matrix,
        /// <b>inv()</b> is its inverse, <b>exp</b> is the exponential operator, <b>x'</b> is the
        /// transposed vector of <b>x</b> and <b>N</b> is the dimension of the vectors <b>x</b> and
        /// <b>m</b>.
         *
        /// @param feature the feature to score
        /// @return the score, in log, for the given feature
         */
        float getScore(float[] feature);

        /**
        /// Pre-compute factors for the Mahalanobis distance. Some of the Mahalanobis distance
        /// computation can be carried out in advance. Specifically, the factor containing only variance
        /// in the Gaussian can be computed in advance, keeping in mind that the the determinant of the
        /// covariance matrix, for the degenerate case of a mixture with independent components - only
        /// the diagonal elements are non-zero - is simply the product of the diagonal elements. <p/>
        /// We're computing the expression: <p/> <p><b>{sqrt((2/// PI) ^ N)/// det(Var))}</b></p>
         *
        /// @return the precomputed distance
         */
        float precomputeDistance();

        /** Applies transformations to means and variances. */
        void transformStats();

        IMixtureComponent clone();
    }
}
